package com.course.chapter3;

/**
 *  懒汉式
 *  优缺点
 *   1.线程安全性  no
 *   2.性能       yes
 *   3.懒加载     yes
 * @ClassName: com.course.chapter3.LazySingleton.java
 * @author: songxulin
 * @date :  2020-06-30 19:01
 * @version V1.0
 */
public class LazySingleton {
    private static LazySingleton singleton ;
    /**
     * 私有化构造方法
     */
    private LazySingleton() {
    }

    public static LazySingleton getInstance() {
        if(singleton == null){
            singleton = new LazySingleton();
        }
        return singleton;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()->{
                LazySingleton instance = LazySingleton.getInstance();
                System.out.println(instance);
            }).start();
        }

    }
}
